package main

import (
	"log"
	"os"
	"text/template"
)

func main() {
	t := template.Must(template.ParseGlob("./views/*.tpl"))

	t.ExecuteTemplate(os.Stdout, "demo", "欢迎访问tizi365.com")

	//定义struct模版参数
	type User struct {
		Name string
	}

	type Order struct {
		Id       int
		Title    string
		Customer User //嵌套字段
	}

	//初始化模版参数
	food := Order{
		Id:       1,
		Title:    "柠檬",
		Customer: User{"李大春"},
	}

	////渲染demo模版, 模版参数为food
	err := t.ExecuteTemplate(os.Stdout, "demo1", food)
	if err != nil {
		log.Println("executing template:", err)
	}
}
